################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Observational Analysis ESS
#Figure 3
#
#Verena Fetscher
#July 2022
####################

####################
# Load data
####################
source("dataframes.R")



##########################
#Produces Figure 3: Average support for redistribution and benefit concentration (above mean earners, 2002-2014).
##########################


data_imputed_sample%>%
  filter(income.dist.th>0)%>%
  ggplot(aes(x = benefitsAvg, y = redistribution,label=country)) +
  stat_summary(fun.data = mean_se,aes(color="rich"),alpha=.5)+
  geom_smooth(method=lm,se=F,color="grey20",na.rm=T,size=.5)+
  xlab("Benefit concentration")+ ylab("Support redistribution")+
  coord_cartesian(ylim=c(2.5, 4.7), xlim=c(0,.95))+
  stat_summary(aes(label=country), fun="mean", geom="text", 
               hjust=0.5, vjust=-.8,size=6)+
  scale_colour_manual(name="Income group", 
                      values=c("grey20"),
                      breaks = c("rich"),
                      labels = c("rich")
  )+
  scale_x_continuous(expand = c(0, 0)) + 
  scale_y_continuous(expand = c(0, 0)) +
  theme_bw()+
  theme(panel.border=element_blank(),axis.line=element_line(),
        legend.position="none",legend.text = element_text(size = 18),
        legend.title = element_text(size=18),axis.text=element_text(size=18),
        axis.title=element_text(size=22)
  )



#Check numbers
data_imputed_sample%>%
  group_by(country)%>%
  filter(income.dist.th>=0)%>%
  summarize(redistribution=mean(redistribution))


##########################
#Save figure
##########################

ggsave(file="figure_3.pdf", height = 5.83, width = 8.27, units = "in")

